<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ include file="../common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>直属分润汇总查询</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="<s:url value="/css/common.css"/>"/>
<script type="text/javascript" src="<c:url value="/js/common.js" />"></script>
<script type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery-1.9.1.js" />"></script>
<script type="text/javascript" src="<c:url value="/js/tabcontrol/TabPanel.js" />"></script>
<script type="text/javascript">

$(document).ready(function(){
    $("#inputAccountNo").bind("blur",queryAgent);  
});

function queryAgent(){
		var accountNo = $("#inputAccountNo").val(); 
    	$.ajax({
    		url:'<c:url value="/profit/getOpertorsByAccountNo.ct" />',
	  		data:{"accountNo":accountNo},
	  		dataType:"json",
	  		type:"POST",
	  		success:function(result){
	  			
	  			if(result.code == "success"){
	  				 $("#agentId").val(result.message);
	  			}else{
	  				console.log(result);
	  				alert(result.message);
	  			}
	  		},error:function(rsg){
	  			alert("代理商账号对应的代理商不存在");
	  		}
    	});
}
//查询结算信息
function queryCheck(){
	if(timeCheck()){
		$("#queryId").attr("disabled",true);
		$("#queryForm").attr("action",'<c:url value="/profit/queryProfitDASum.ct" />')
		$("#queryForm").submit();
	}
	
}
//导出excel	
function exportCheck(){
	if(timeCheck()){
		$("#szPower").attr("disabled",true);
		$("#queryId").attr("disabled",false);
		$("#queryForm").attr("action",'<c:url value="/profit/exportProfitDASum.ct" />')
		$("#queryForm").submit();
	}
}


//表单条件校验
function timeCheck(){
	var minDate = $.trim($("#beginTime").val());
	var maxDate = $.trim($("#endTime").val());
	
	if(!minDate || !maxDate ){
		alert("请选择时间范围");
		return false;
	}
	
	var date1=str2date(minDate);
	var date2=str2date(maxDate);
	
	if(date1.getMonth()!=date2.getMonth()){
	    alert("选择的时间范围不在同一个月内！");
		return false;
	}
	
	return true;
}


//字符串转时间
function   str2date(str){   
	var   d=null;   
	var   reg=/^(\d{4})(\d{2})(\d{2})$/  ;
	if(arr=str.match(reg)) d=new Date(Number(arr[1]),Number(arr[2])-1,Number(arr[3])) ; 
	return   d;   
}

	
</script>



</head>

<body>
<s:form id="queryForm" action="/profit/queryProfitDASum.ct" method="post" theme="simple">
<table class="tb">
    <tbody>
        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h2">POS收单运营管理平台</div></td>
        </tr>

        <tr class="tb-line">
            <td class="tb-td" colspan="4"><div class="tb-h3">直属分润汇总查询</div></td>
        </tr>
         <tr class="tb-line">
        	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
                <div class="tb-h4">结算日期：</div>
            </td>
            <td class="tb-td">
                <label class="tb-input-mini"><s:textfield id="beginTime"  name="searchCondition.beginTime" 
                onfocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});" 
                /></label>-<label class="tb-input-mini"><s:textfield id="endTime"  name="searchCondition.endTime" 
                onfocus="WdatePicker({dateFmt:'yyyyMMdd',readOnly:true,wdate:true,errDealMode:0});" 
                /></label><code class="asterisk">*</code>
            </td>
            <td width="12%" style="min-width: 150px" align="right" class="tb-td">
                <div class="tb-h4">代理商：</div>
            </td>
            <td class="tb-td">
                <label class="tb-select">
                    <s:select id="agentId" name="searchCondition.id" cssClass="queryWidth" list="#request.agnetList" listKey="key" listValue="value" headerKey="-1" headerValue="--请选择--"></s:select>
                </label>
                 <label class="tb-input-normal"><s:textfield   id="inputAccountNo"  placeholder="请输入代理商账号"   /> </label>
                
            </td>
         </tr>
         <tr class="tb-line">
        	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
                <div class="tb-h4">汇总：</div>
            </td>
            <td class="tb-td">
             <s:select cssClass="queryWidth" name="searchCondition.totalType" id="totalType" list="#{'1':'交易类型','2':'卡类型'}" listKey="key" listValue="value" headerKey="-1" headerValue="--不限--"/> 
            </td>
         </tr>
       <%--  <tr class="tb-line">
            <td class="tb-td line-submit" align="right" colspan="4">
                <label class="tb-input-submit">
                    <s:submit  value="查 询" />
                </label>
                <label class="tb-input-submit">
                   <s:reset value="取 消" />
                </label>
            </td>
        </tr> --%>
        
        <tr class="tb-line">
            <td class="tb-td line-submit" align="right" colspan="4">
                <label class="tb-input-submit">
                    <input id="queryId"  type="button" value="查询" onclick="return queryCheck();"/>
                </label>
                <label class="tb-input-submit">
                	<s:if test="#request.searchRsList != null && #request.searchRsList.size>0">
					   		<input id="szPower" type="button"
							value="导 出" onclick="return exportCheck();"/>
					   
					</s:if>
					<s:else>
					 	<input id="szPower" disabled="disabled" value="导  出" type="button" /> 
					</s:else>
                </label>
            </td>
        </tr>
    </tbody>
</table>
	
			

<div class="big-tb">
    <table class="tb" style="width: 100%;">
        <thead>
        	<tr class="tb-line">
				<td colspan="12" align="center"><span style="font-color: red"><s:actionerror /></span>
					<span style="font-color: red;"><s:actionmessage /></span > <span style="font-color: red;"><s:fielderror /></span>
					<span id="otherError"></span>
				</td>
			</tr>
            <tr class="tb-line">
                <th class="tb-th"  colspan="12">直属分润汇总查询列表</th>
            </tr>
            <s:if test="#request.searchRsList != null && #request.searchRsList.size>0" >
					<tr class="tb-line">
						<td class="tb-td paging"  colspan="12"> 
							<page:pageCount max_pages="11" totalPage="${requestScope.totalPage}" currentPage="${requestScope.currentPage}" action="${rootPath}/profit/queryProfitDASum.ct?currentPage=" />
						</td>
					</tr>
				</s:if>
            <tr class="tb-line bg-gray">
                <th class="tb-th">代理商名称</th>
                <s:if test="#request.totalType ==1">
                 <th class="tb-th">交易类型</th>
                </s:if>
                <s:elseif test="#request.totalType ==2">
                 <th class="tb-th">卡类型</th>
                </s:elseif>
                <s:else>
                 <th class="tb-th">卡类型</th>
                 <th class="tb-th">交易类型</th>
                </s:else>
                <th class="tb-th">总笔数</th>
                <th class="tb-th">总金额</th>
                <th class="tb-th">分润数据</th>
                <th class="tb-th">分润比例</th>
                <th class="tb-th">实际分润</th>
                <th class="tb-th">结算时间</th>
            </tr>
        </thead>
        <tbody>
		<s:iterator value="#request.searchRsList" status="stat" id="oper">
						<tr class="tb-line">
							<td class="tb-td" ><s:property value="#oper.agentName" /></td>
							<s:if test="#request.totalType ==1">
								<td class="tb-td" ><s:property value="#oper.prodCd" /></td>
			                </s:if>
			                <s:elseif test="#request.totalType ==2">
				                <td class="tb-td" ><s:property value="#oper.cardClass" /></td>
			                </s:elseif>
			                <s:else>
			                	<td class="tb-td" ><s:property value="#oper.prodCd" /></td>
				                <td class="tb-td" ><s:property value="#oper.cardClass" /></td>
			                </s:else>
			                <td class="tb-td" ><s:property value="#oper.TCount" /></td>
							<td class="tb-td" ><s:property value="#oper.SAmt" /></td>
							<td class="tb-td" ><s:property value="#oper.merfee" /></td>
							<td class="tb-td" ><s:property value="#oper.percent" /></td>
							<td class="tb-td" ><s:property value="#oper.realMerfee" /></td>
							<td class="tb-td" ><s:property value="#oper.createDate" /></td>
						</tr>
					</s:iterator>
        </tbody>
    </table>
</div>
</s:form>
	<s:if test="#request.info_request !=null">
	<script language="javascript">
	    alert("${request.info_request}");
	    </script>
	</s:if>	
</body>
</html>
